package _2TCP;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class TCPClient {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) throws UnknownHostException, IOException {
		String host = "10.129.122.172";
		int port = 8888;
		Socket s = new Socket(host,port);
		
		BufferedReader bufferedReaderServer = new BufferedReader(new InputStreamReader(s.getInputStream()));
		BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
		
		//和服务器端通信
		System.out.print("请输入：");
        String message = "";
        while ((message = sc.next()) != null) {
            bufferedWriter.write(message);
            bufferedWriter.newLine();
            bufferedWriter.flush();
            String getMessage = bufferedReaderServer.readLine();
            System.out.println("来自服务器说：" + getMessage);
            System.out.print("请输入：");
        }
        
        s.close();
//		// 1. 创建socket，连上服务器
//				String host = "10.129.122.172";
//				int port = 8888;
//				Socket s = new Socket(host,port);
//				
//				// 2. 读写数据
//				InputStream in = s.getInputStream();
//				OutputStream out = s.getOutputStream();
//				
//				
//				byte[] buf = new byte[1024];
//				int len = in.read(buf);
//				String str = new String(buf,0,len);
//				System.out.println("接收到服务器发来信息"+str);
//				
//				System.out.println("给服务器发:收到了");
//				out.write("收到了".getBytes());
//				
//				// 5.2 接收信息
//				s.close();
	}
}